package com.xzy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

public class Data {
	private String reString;
	private String inputLine;
	private HttpURLConnection httpURLConnection;
	private String httpUrl;

	public String getData() {
		httpUrl = "http://count49.duapp.com/data";
		reString = "";
		httpURLConnection = null;
		URL url;
		try {
			url = new URL(httpUrl);
			if (url != null) {
				httpURLConnection = (HttpURLConnection) url.openConnection();
				httpURLConnection.setConnectTimeout(3000);
				httpURLConnection.setDoInput(true);
				httpURLConnection.setRequestMethod("GET");
				int responseCode = httpURLConnection.getResponseCode();
				if (responseCode == 200) {
					InputStreamReader in = new InputStreamReader(
							httpURLConnection.getInputStream());
					BufferedReader buffer = new BufferedReader(in);
					inputLine = null;
					while (((inputLine = buffer.readLine()) != null)) {
						// ������ÿһ�к������һ��"\n"4����
						reString += inputLine + "\n";
					}
					// TextView.setText(reString);
					// �ر�InputStreamReader
					in.close();
					// �ر�httpl��
					httpURLConnection.disconnect();
				}
			}
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return reString;
		
		//System.out.println("str对应返回的字符串\n");
//		Gson gson = new Gson();
//		List<DataInfo> ls = gson.fromJson(str, new TypeToken<List<DataInfo>>(){}.getType());//返回对象列表
//		for(int i = 0; i < ls.size() ; i++)
//		{
////		     DataInfo p = ls.get(i);获得一个Datainfo对象
////		     System.out.println(p.getId());
////		}
	}
}